<?php
/**
 * +--------------------------------------------------------+
 * @Created by Phpstorm.
 * @Category InformationController.php
 * @Depiction
 * @Author hwy <429208948@qq.com>
 * @Date 2022/6/22  20:07
 * +--------------------------------------------------------+
 */

namespace App\Http\Controllers\Admin\V1;

use App\Services\InformationService;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class InformationController extends Controller
{
    private $informationService;

    public function __construct(InformationService $informationService)
    {
        $this->informationService = $informationService;
    }

    public function index(Request $request)
    {
        $cache_name = 'number_collect_article';
        $cache_ttl  = Carbon::now()->addSeconds(20);
        $number     = Cache::remember($cache_name, $cache_ttl, function () {
            return $number = $this->informationService->getNumber();
        });

        $list = $this->informationService->getList($request);
        $data = [
            'number' => $number,
            'list'   => $list,
        ];

        return $this->responseSuccessData('请求成功！', $data);
    }

}
